<?php
namespace Agent\Controller;

use Think\Model;
class AgentController extends CommonController {
	
public function __construct() {
		parent::__construct ();
		parent::__config ( array (
				'model_name'=>'Agent',
		) );
	}
	
	public function index(){
		parent::__config ( array (
		) );
		$table =I('table');
		if (!$table == null && ! empty ($table)) {
			parent::__config ( array (
					'display' => 'table' ,
					'display_parms'=>array('table'=>1),
			) );
		};
		parent::index ();
	}
	
	function add() {
	}
	function insert() {
	}
	
	function contact() {
		$this->display();
	}
	
	function bean_lj() {
		$agent_info = session("ssc_agent");
		$code = encrypt2($agent_info['agent_code']);
		$lj = "http://".$_SERVER['HTTP_HOST']."/index.php/Home/User/register?code=".$code;
		$this->assign('code',$agent_info['agent_code']);
		$this->assign('lj',$lj);
		$this->display();
	}
	
	function bean() {
		$agent_info = session("ssc_agent");
		$where['agent_id']=$agent_info['agent_id'];
		$agent = D('Agent')->where($where)->field('agent_id,agent_code,phone,money')->find();
		$code = encrypt2($agent['agent_code']);
		$agent['lj'] = "http://".$_SERVER['HTTP_HOST']."/index.php/Home/User/register?code=".$code;
		$this->assign("vo",$agent);
		$this->display();
	}
	
	function change_password(){
// 		dump(encrypt (123465));
// 		dump(decrypt(encrypt (123465)));
// 		die();
		$this->display();
	}
	
	function foreverdelete() {
	}
	
	function edit() {
	}
	
	function update() {
		$new_password1 = I("new_password1");
		$new_password2 = I("new_password2");
		if($new_password1!=$new_password2){
			$this->system_hint("确认密码与新密码不相同!", 101);
		}else{
			$agent_info = session("ssc_agent");
			$where['agent_id']=$agent_info['agent_id'];
			$agentModel = 	D('Agent');
			$agent_find = $agentModel->where($where)->field('password')->find();
			if (decrypt ( $agent_find ['password'] ) == I ( 'ord_password' )) {
				$data['agent_id']=$agent_info['agent_id'];
				$data['password']= encrypt ($new_password1);
				$agentModel->save($data);
				$this->system_hint("密码修改成功!", 100,2);
			}else{
				$this->system_hint("旧密码不正确!", 101);
			}
		}
	}
	function logout(){
		session("ssc_agent",null);
		session('agent',null);
		$this->redirect('Home/Index/index');
	}
	

	function sort() {
		parent::sort ();
	}
	
	function excelImport(){
	}
	
	function excelOutput(){
		
	}
	
}